# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup
from ..base_parser import BasePageParser


class CateList1Parser(BasePageParser):
    """新闻列表页解析器"""
    
    def can_handle(self, response):
        """判断是否为新闻列表页"""
        # 只处理列表页，不处理详情页
        return 'qzxrzxxgb' in response.url or 'jsjdxxgb' in response.url or 'qtcp_zyx' in response.url
    
    def parse(self, response):
        self.logger.info(f"正在解析列表页: {response.url}")
        
        soup = BeautifulSoup(response.text, 'html.parser')
        
        links = soup.select("a.orange")
        
        
        for link in links:
            href = link.get('href')
            if href and 'certSearch/search' in href:
                detail_url = self.urljoin(response.url, href)
                
                yield self.make_request(
                    detail_url,
                    callback=self.spider.parse,  # 返回主spider进行路由
                    meta={
                        'category_url': response.url,
                        'page_type': 'cccf_product_list',
                        'categorys': [link.get_text(strip=True)],
                    }
                ) 